/**
 * @author Stephan Pfaff (http://www.derdaumen.net)
 */

/**
 * The Project Object
 * @param vars object providing the project properties (loaded from the database)
 * @return
 */
function Project(vars){
	if (vars != null) {
		try {
			Item.call(this, vars.prefix, vars.id, vars.type, vars.basename, vars.path, vars.label, vars.alias, vars.thumb, vars.thumb_enable, false, vars.item_class);
			this.category_id = parseInt(vars.category_id);
			this.position 	= parseInt(vars.position);
			this.link			= vars.link;
			this.link_enable	= vars.link_enable;
		} catch(e) {
			if(debug) alert('Initialization of Project failed, missing or wrong parameter! ('+e+')');
		}
	} else {
		try {
			Item.call(this,
					'prj',
					0,
					"project",
					getCategories().currentItem().alias +'_'+$('#prj_alias').val(),
					getCategories().currentItem().alias +'/'+$('#prj_alias').val()+'/',
					'',
					$('#prj_alias').val(),
					'',
					false,
					false,
					'');
			this.category_id = getCategories().currentItem().id;
			this.position 	= 0;
		} catch (e) {
			if(debug) alert('Initialization of new empty Project failed, missing or wrong parameter! ('+e+')');
		}
	}
};

Project.prototype = new Item();
Project.prototype.category_id = 0;
Project.prototype.position = 0;
Project.prototype.link = "";
Project.prototype.link_enable = false;

/**
 * Loads the project's children.
 */
Project.prototype.loadChilds = function() {
	getButtons().load({prefix: getButtons().prefix, ctg_id: this.category_id, prj_id: this.id}, null, false);
};
/**
 * Checks if all the mandatory inputs for a updating/saving a project are correct. 
 */
Project.prototype.check = function() {
	getProjects().hideErrorMessages();
	var isValid = true;
	var prj_alias = $('#prj_alias').val() == '' ? false : true;
	var prj_label = $('#prj_label').val() == '' ? false : true;
	var prj_thumb = $('#prj_thumb_path').val() == '' ? false : true;
	var prj_thumb_enable = $('#prj_thumb_enable').is(':checked');
	var prj_link = $('#prj_link').val() == '' ? false : true;
	var prj_link_enable = $('#prj_link_enable').is(':checked');
	if (!prj_alias) {
		isValid = false;
		$('#'+this.prefix+'_alias').showError('Alias darf nicht leer sein!');
	}
	if (!prj_label && !prj_thumb) {
			isValid = false;
			$('#'+this.prefix+'_label').showError('Ohne Thumbnail ist ein Label notwendig!');
			$('#'+this.prefix+'_thumb_container').showError('Kein Label erfordert ein Thumbnail!');
	} else if (prj_thumb && !prj_thumb_enable) {
			isValid = false;
			$('#'+this.prefix+'_label').showError('Ohne Thumbnail ist ein Label notwendig!');
			$('#'+this.prefix+'_thumb_enable').showError('Ohne Label muss Thumbnail aktiv sein!');
	}
	return isValid;
};